#include <bits/stdc++.h>

using namespace std;
#define int long long
const int inf = 0x3f3f3f3f;

void solve()
{
	int k, a, b, x, y;
	cin >> k >> a >> b >> x >> y;
	if (x == y)
	{
		if (k >= min(a, b)) cout << (k - min(a, b)) / x + 1 << endl;
		else cout << 0 << endl;
	}
	else if (x > y)
	{
		int ans = 0;
		if (k >= b) ans += (k - b) / y + 1, k -= y * ((k - b) / y + 1);
		if (k >= a) ans += (k - a) / x + 1;
		cout << ans << endl;
	}
	else
	{
		int ans = 0;
		if (k >= a) ans += (k - a) / x + 1, k -= x * ((k - a) / x + 1);
		if (k >= b) ans += (k - b) / y + 1;
		cout << ans << endl;
	}
}

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int _ = 1;
	cin >> _;
	while (_--)
	{
		solve();
	}
	return 0;
}